package cst.a720yyq.zyfypt_720yyq.Modle;


import java.util.List;


import cst.a720yyq.zyfypt_720yyq.Bean.FocusResult;
import cst.a720yyq.zyfypt_720yyq.Bean.UserBean;
import cst.a720yyq.zyfypt_720yyq.Interface.FocusListListener;
import cst.a720yyq.zyfypt_720yyq.Interface.FocusListService;
import cst.a720yyq.zyfypt_720yyq.Interface.FocusListface;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


/**
 * Created by Administrator on 2017/6/7 0007.
 */

public class FocusListModel implements FocusListface<UserBean> {
    private Retrofit retrofit;
    private String BASEURL
            ="http://amicool.neusoft.edu.cn/";
    //构造函数
    public FocusListModel()
    {   //使用Retrofit----1
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    @Override
    public void getResultList(String mod, int page, String sessionID, final FocusListListener listener) {
        //使用Retrofit----2
        FocusListService service
                =retrofit.create(FocusListService.class);
        Call<List<FocusResult<UserBean>>> call
                =service.getFocusUserList(mod,page,sessionID);
        //使用Retrofit----3
        call.enqueue(new Callback<List<FocusResult<UserBean>>>() {
            @Override
            public void onResponse(Call<List<FocusResult<UserBean>>> call, Response<List<FocusResult<UserBean>>> response) {
                if(response.isSuccessful() && response!=null)
                {  listener.onResponse(response.body());
                }
                else   listener.onFail("onresponse fail");
            }
            @Override
            public void onFailure(Call<List<FocusResult<UserBean>>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }

}

